﻿
using MemberPoint.Entity.ViewModel;
using MMPS.Business;
using MMPS.Common;
using MMPS.Entity.POCOMdel;
using MMPS.Entity.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MemberPoint.Business
{
   public class GiftsService: BaseService<ExchangGifts>
    {                                                           
        # region 显示礼品列表
        public OperateResult GetGifts(GiftSViewModel Gifts)
        {
            var query = PredicateExtensions.True<ExchangGifts>();
            int rowCount = 0;
            var pageDate = GetList(Gifts.page, Gifts.rows, ref rowCount, query, s => s.EG_ID, true).Select(u => new GiftSViewModel
            {
                EG_ID = u.EG_ID,
                EG_ExchangNum = u.EG_ExchangNum,
                EG_GiftCode = u.EG_GiftCode,
                EG_GiftName = u.EG_GiftName,
                EG_Number = u.EG_Number,
                EG_Photo = u.EG_Photo,
                EG_Point = u.EG_Point,
                EG_Remark = u.EG_Remark,
                S_ID = u.S_ID,
            }).ToList();
            var pageViewModel = new DatgRIDViewModel { total = rowCount, rows = pageDate };
            return new OperateResult(ResultStatus.Success, "", pageViewModel);
        }
        #endregion

        #region 添加礼品
        public OperateResult GetAddGifts(GiftSViewModel Gifts)
        {

            ExchangGifts EG = new ExchangGifts();
            EG.EG_ID = Gifts.EG_ID;
            EG.EG_ExchangNum = Gifts.EG_ExchangNum;
            EG.EG_GiftCode = Gifts.EG_GiftCode;
            EG.EG_GiftName = Gifts.EG_GiftName;
            EG.EG_Number = Gifts.EG_Number;
            EG.EG_Photo = Gifts.EG_Photo;
            EG.EG_Point = Gifts.EG_Point;
            EG.EG_Remark = Gifts.EG_Remark;
            EG.S_ID = Gifts.S_ID;
            var result = Add(EG);
            if (result)
            {
                return new OperateResult(ResultStatus.Success, "添加成功");
            }
            else
            {
                return new OperateResult(ResultStatus.Error, "添加失败");
            }

        }
        #endregion

        #region 修改礼品
        public OperateResult GetUpdateGifts(int id)
        {

            var list = Find(e => e.EG_ID == id);
            if (list != null)
            {
                GiftSViewModel GVW = new GiftSViewModel();
                GVW.EG_ID = list.EG_ID;
                GVW.EG_ExchangNum = list.EG_ExchangNum;
                GVW.EG_GiftCode = list.EG_GiftCode;
                GVW.EG_GiftName = list.EG_GiftName;
                GVW.EG_Number = list.EG_Number;
                GVW.EG_Photo = list.EG_Photo;
                GVW.EG_Point = list.EG_Point;
                GVW.EG_Remark = list.EG_Remark;
                GVW.S_ID = list.S_ID;
                return new OperateResult(ResultStatus.Success, "修改显示成功", GVW);
            }
            else
            {
                return new OperateResult(ResultStatus.Error, "修改显示异常");
            }

        }
        public OperateResult GetUpdateGifts(GiftSViewModel Gifts)
        {
            var list = Find(e => e.EG_ID == Gifts.EG_ID);
            ExchangGifts EG = new ExchangGifts();
            list.EG_ID = Gifts.EG_ID;
            list.EG_ExchangNum = Gifts.EG_ExchangNum;
            list.EG_GiftCode = Gifts.EG_GiftCode;
            list.EG_GiftName = Gifts.EG_GiftName;
            list.EG_Number = Gifts.EG_Number;
            list.EG_Photo = Gifts.EG_Photo;
            list.EG_Point = Gifts.EG_Point;
            list.EG_Remark = Gifts.EG_Remark;
            list.S_ID = Gifts.S_ID;
            var result = Update(list);
            if (result)
            {
                return new OperateResult(ResultStatus.Success, "修改成功");
            }
            else
            {
                return new OperateResult(ResultStatus.Error, "修改失败");
            }
        }
        #endregion

        #region 删除礼品
        public OperateResult Delete(int id)
        {

            var list = Find(e => e.EG_ID == id);
            if (list != null)
            {
                var result = Delete(list);
                if (result)
                {
                    return new OperateResult(ResultStatus.Success, "删除成功");
                }
                else
                {
                    return new OperateResult(ResultStatus.Error, "删除失败");
                }

            }
            else
            {
                return new OperateResult(ResultStatus.Error, "该用户异常");
            }

        }
        #endregion
    }
}
